<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>Document</title>
    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
<div id="app"><h2>广播demo</h2></div>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        {{--const uid = {{ $uid ?? 0 }}; // 将 PHP 变量 $uid 传递给 JavaScript--}}
        {{--Echo.private(`Test.Channel.${uid}`) // 监听私有频道--}}
        {{--    .listen('.test.name', (e) => {  // 监听广播名称--}}
        {{--        console.log(`私有频道 Test.Channel.${uid}`);--}}
        {{--        console.log(e);--}}
        {{--    });--}}


       const ws = new WebSocket('wss://learn.yuxibs.com/wss')
        ws.onopen = function (event) {
            console.log('WebSocket is open now.');
        };
        ws.onmessage = function (event) {
            console.log('WebSocket message received:', event.data);
        };
        ws.onclose = function (event) {
            console.log('WebSocket is closed now.');
        };
    });
</script>
</body>
</html>
